home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Applications / NIH Image 1.62b11 / src / Macros2.p < prev    next >
Text File  |  1996-11-26  |  50KB  |  2,014 lines

  1. unit Macros2;
  2. {Loads macro files into memory and converts them into a token stream}
  3. {that is interpreted by the routines in macros1.p.}
  4.  
  5.  
  6. interface
  7.  
  8.     uses
  9.         Types, Memory, QuickDraw, Packages, Menus, Events, Fonts, Scrap, ToolUtils,
  10.         Resources, Errors, Palettes, Files, Globals, Utilities, Graphics, File2;
  11.  
  12.     procedure LoadMacrosFromFile (fname: str255; RefNum: integer);
  13.     procedure LoadMacros;
  14.  
  15.  
  16. implementation
  17.  
  18.     type
  19.         MacroBufType = packed array[0..MaxMacroFileSize] of char;
  20.         MacroBufPtr = ^MacroBufType;
  21.     var
  22.         PC2, StartOfLine: integer;
  23.         MacroBufP: MacroBufPtr;
  24.  
  25.  
  26.     procedure InitSymbolTable;
  27.         var
  28.             i: integer;
  29.     begin
  30.         with MacrosP^ do begin
  31.                 for i := 1 to MaxSymbols do
  32.                     with SymbolTable[i] do begin
  33.                             tType := CommandT;
  34.                             cType := NullC;
  35.                             loc := 0;
  36.                         end;
  37.  
  38.                 with SymbolTable[1] do begin
  39.                         symbol := 'begin       ';
  40.                         tType := BeginT;
  41.                     end;
  42.                 with SymbolTable[2] do begin
  43.                         symbol := 'convolve    ';
  44.                         cType := ConvolveC;
  45.                     end;
  46.                 with SymbolTable[3] do begin
  47.                         symbol := 'fill        ';
  48.                         cType := FillC;
  49.                     end;
  50.                 with SymbolTable[4] do begin
  51.                         symbol := 'selectall   ';
  52.                         cType := SelectC;
  53.                     end;
  54.                 with SymbolTable[5] do begin
  55.                         symbol := 'invert      ';
  56.                         cType := InvertC;
  57.                     end;
  58.                 with SymbolTable[6] do begin
  59.                         symbol := 'killroi     ';
  60.                         cType := KillC;
  61.                     end;
  62.                 with SymbolTable[7] do begin
  63.                         symbol := 'markselectio';
  64.                         cType := MarkC;
  65.                     end;
  66.                 with SymbolTable[8] do begin
  67.                         symbol := 'drawboundary';
  68.                         cType := FrameC;
  69.                     end;
  70.                 with SymbolTable[9] do begin
  71.                         symbol := 'measure     ';
  72.                         cType := MeasureC;
  73.                     end;
  74.                 with SymbolTable[10] do begin
  75.                         symbol := 'fliphorizont';
  76.                         cType := FliphC;
  77.                     end;
  78.                 with SymbolTable[11] do begin
  79.                         symbol := 'analyzeparti';
  80.                         cType := AnalyzeC;
  81.                     end;
  82.                 with SymbolTable[12] do begin
  83.                         symbol := 'nextwindow  ';
  84.                         cType := NextC;
  85.                     end;
  86.                 with SymbolTable[13] do begin
  87.                         symbol := 'paste       ';
  88.                         cType := PasteC;
  89.                     end;
  90.                 with SymbolTAble[14] do begin
  91.                         symbol := 'clear       ';
  92.                         cType := ClearC;
  93.                     end;
  94.                 with SymbolTable[15] do begin
  95.                         symbol := 'copy        ';
  96.                         cType := CopyC;
  97.                     end;
  98.                 with SymbolTable[16] do begin
  99.                         symbol := 'restoreroi  ';
  100.                         cType := RestoreC;
  101.                     end;
  102.                 with SymbolTable[17] do begin
  103.                         symbol := 'setthreshold';
  104.                         cType := ThresholdC;
  105.                     end;
  106.                 with SymbolTable[18] do begin
  107.                         symbol := 'resetgraymap';
  108.                         cType := ResetgmC;
  109.                     end;
  110.                 with SymbolTable[19] do begin
  111.                         symbol := 'makebinary  ';
  112.                         cType := MakeBinC;
  113.                     end;
  114.                 with SymbolTable[20] do begin
  115.                         symbol := 'dither      ';
  116.                         cType := DitherC;
  117.                     end;
  118.                 with SymbolTable[21] do begin
  119.                         symbol := 'smooth      ';
  120.                         cType := SmoothC;
  121.                     end;
  122.                 with SymbolTable[22] do begin
  123.                         symbol := 'scalemath   ';
  124.                         cType := ScaleMathC;
  125.                     end;
  126.                 with SymbolTable[23] do begin
  127.                         symbol := 'sharpen     ';
  128.                         cType := SharpenC;
  129.                     end;
  130.                 with SymbolTable[24] do begin
  131.                         symbol := 'inverty     ';
  132.                         cType := InvertYC;
  133.                     end;
  134.                 with SymbolTable[25] do begin
  135.                         symbol := 'calibrated  ';
  136.                         tType := FunctionT;
  137.                         cType := CalibratedC;
  138.                     end;
  139.                 with SymbolTable[26] do begin
  140.                         symbol := 'divide      ';
  141.                         cType := DivC;
  142.                     end;
  143.                 with SymbolTable[27] do begin
  144.                         symbol := 'redirect    ';
  145.                         cType := RedirectC;
  146.                     end;
  147.                 with SymbolTable[28] do begin
  148.                         symbol := 'getresults  ';
  149.                         cType := GetResultsC;
  150.                     end;
  151.                 with SymbolTable[29] do begin
  152.                         symbol := 'wait        ';
  153.                         cType := WaitC;
  154.                     end;
  155.                 with SymbolTable[30] do begin
  156.                         symbol := 'resetcounter';
  157.                         cType := ResetmC;
  158.                     end;
  159.                 with SymbolTable[31] do begin
  160.                         symbol := 'setdensitysl';
  161.                         cType := SetSliceC;
  162.                     end;
  163.                 with SymbolTable[32] do begin
  164.                         symbol := 'undo        ';
  165.                         cType := UndoC;
  166.                     end;
  167.                 with SymbolTable[33] do begin
  168.                         symbol := 'setforegroun';
  169.                         cType := SetForeC;
  170.                     end;
  171.                 with SymbolTable[34] do begin
  172.                         symbol := 'setbackgroun';
  173.                         cType := SetBackC;
  174.                     end;
  175.                 with SymbolTable[35] do begin
  176.                         symbol := 'scaleandrota';
  177.                         cType := ScaleC;
  178.                     end;
  179.                 with SymbolTable[36] do begin
  180.                         symbol := 'rotateright ';
  181.                         cType := RotateRC;
  182.                     end;
  183.                 with SymbolTable[37] do begin
  184.                         symbol := 'rotateleft  ';
  185.                         cType := RotateLC;
  186.                     end;
  187.                 with SymbolTable[38] do begin
  188.                         symbol := 'traceedges  ';
  189.                         cType := TraceC;
  190.                     end;
  191.                 with SymbolTable[39] do begin
  192.                         symbol := 'multiply    ';
  193.                         cType := MulC;
  194.                     end;
  195.                 with SymbolTable[40] do begin
  196.                         symbol := 'showhistogra';
  197.                         cType := HistoC;
  198.                     end;
  199.                 with SymbolTable[41] do begin
  200.                         symbol := 'enhancecontr';
  201.                         cType := EnhanceC;
  202.                     end;
  203.                 with SymbolTable[42] do begin
  204.                         symbol := 'equalizehist';
  205.                         cType := EqualizeC;
  206.                     end;
  207.                 with SymbolTable[43] do begin
  208.                         symbol := 'erode       ';
  209.                         cType := ErodeC;
  210.                     end;
  211.                 with SymbolTable[44] do begin
  212.                         symbol := 'dilate      ';
  213.                         cType := DilateC;
  214.                     end;
  215.                 with SymbolTable[45] do begin
  216.                         symbol := 'outline     ';
  217.                         cType := OutlineC;
  218.                     end;
  219.                 with SymbolTable[46] do begin
  220.                         symbol := 'skeletonize ';
  221.                         cType := ThinC;
  222.                     end;
  223.                 with SymbolTable[47] do begin
  224.                         symbol := 'addconstant ';
  225.                         cType := AddConstC;
  226.                     end;
  227.                 with SymbolTable[48] do begin
  228.                         symbol := 'reverttosave';
  229.                         cType := RevertC;
  230.                     end;
  231.                 with SymbolTable[49] do begin
  232.                         symbol := 'shadow      ';
  233.                         cType := ShadowC;
  234.                     end;
  235.                 with SymbolTable[50] do begin
  236.                         symbol := 'flipvertical';
  237.                         cType := FlipvC;
  238.                     end;
  239.                 with SymbolTable[51] do begin
  240.                         symbol := 'end         ';
  241.                         tType := EndT;
  242.                     end;
  243.                 with SymbolTable[52] do begin
  244.                         symbol := 'getline     ';
  245.                         cType := GetLineC;
  246.                     end;
  247.                 with SymbolTable[53] do begin
  248.                         symbol := 'var         ';
  249.                         tType := VarT;
  250.                     end;
  251.                 with SymbolTable[54] do begin
  252.                         symbol := 'for         ';
  253.                         tType := ForT;
  254.                     end;
  255.                 with SymbolTable[55] do begin
  256.                         symbol := 'integer     ';
  257.                         tType := IntegerT;
  258.                     end;
  259.                 with SymbolTable[56] do begin
  260.                         symbol := 'to          ';
  261.                         tType := ToT;
  262.                     end;
  263.                 with SymbolTable[57] do begin
  264.                         symbol := 'do          ';
  265.                         tType := DoT;
  266.                     end;
  267.                 with SymbolTable[58] do begin
  268.                         symbol := 'beep        ';
  269.                         cType := BeepC;
  270.                     end;
  271.                 with SymbolTable[59] do begin
  272.                         symbol := 'capture     ';
  273.                         cType := CaptureC;
  274.                     end;
  275.                 with SymbolTable[60] do begin
  276.                         symbol := 'makeroi     ';
  277.                         cType := MakeC;
  278.                     end;
  279.                 with SymbolTable[61] do begin
  280.                         symbol := 'moveroi     ';
  281.                         cType := MoveC;
  282.                     end;
  283.                 with SymbolTable[62] do begin
  284.                         symbol := 'insetroi    ';
  285.                         cType := InsetC;
  286.                     end;
  287.                 with SymbolTable[63] do begin
  288.                         symbol := 'moveto      ';
  289.                         cType := MoveToC;
  290.                     end;
  291.                 with SymbolTable[64] do begin
  292.                         symbol := 'drawtext    ';
  293.                         cType := DrawTextC;
  294.                     end;
  295.                 with SymbolTable[65] do begin
  296.                         symbol := 'setfont     ';
  297.                         cType := SetFontC;
  298.                     end;
  299.                 with SymbolTable[66] do begin
  300.                         symbol := 'setfontsize ';
  301.                         cType := SetFontSizeC;
  302.                     end;
  303.                 with SymbolTable[67] do begin
  304.                         symbol := 'settext     ';
  305.                         cType := SetTextC;
  306.                     end;
  307.                 with SymbolTable[68] do begin
  308.                         symbol := 'drawnumber  ';
  309.                         cType := DrawNumC;
  310.                     end;
  311.                 with SymbolTable[69] do begin
  312.                         symbol := 'or          ';
  313.                         tType := orOp;
  314.                     end;
  315.                 with SymbolTable[70] do begin
  316.                         symbol := 'and         ';
  317.                         tType := andOp;
  318.                     end;
  319.                 with SymbolTable[71] do begin
  320.                         symbol := 'div         ';
  321.                         tType := IntDivOp;
  322.                     end;
  323.                 with SymbolTable[72] do begin
  324.                         symbol := 'mod         ';
  325.                         tType := modOp;
  326.                     end;
  327.                 with SymbolTable[73] do begin
  328.                         symbol := 'getpicsize  ';
  329.                         cType := GetPicSizeC;
  330.                     end;
  331.                 with SymbolTable[74] do begin
  332.                         symbol := 'putmessage  ';
  333.                         cType := PutMsgC;
  334.                     end;
  335.                 with SymbolTable[75] do begin
  336.                         symbol := 'exit        ';
  337.                         cType := ExitC;
  338.                     end;
  339.                 with SymbolTable[76] do begin
  340.                         symbol := 'if          ';
  341.                         tType := ifT;
  342.                     end;
  343.                 with SymbolTable[77] do begin
  344.                         symbol := 'then        ';
  345.                         tType := thenT;
  346.                     end;
  347.                 with SymbolTable[78] do begin
  348.                         symbol := 'else        ';
  349.                         tType := elseT;
  350.                     end;
  351.                 with SymbolTable[79] do begin
  352.                         symbol := 'while       ';
  353.                         tType := whileT;
  354.                     end;
  355.                 with SymbolTable[80] do begin
  356.                         symbol := 'repeat      ';
  357.                         tType := repeatT;
  358.                     end;
  359.                 with SymbolTable[81] do begin
  360.                         symbol := 'until       ';
  361.                         tType := untilT;
  362.                     end;
  363.                 with SymbolTable[82] do begin
  364.                         symbol := 'not         ';
  365.                         tType := NotOp;
  366.                     end;
  367.                 with SymbolTable[83] do begin
  368.                         symbol := 'getroi      ';
  369.                         cType := GetRoiC;
  370.                     end;
  371.                 with SymbolTable[84] do begin
  372.                         symbol := 'real        ';
  373.                         tType := RealT;
  374.                     end;
  375.                 with SymbolTable[85] do begin
  376.                         symbol := 'trunc       ';
  377.                         tType := FunctionT;
  378.                         cType := TruncC;
  379.                     end;
  380.                 with SymbolTable[86] do begin
  381.                         symbol := 'round       ';
  382.                         tType := FunctionT;
  383.                         cType := RoundC;
  384.                     end;
  385.                 with SymbolTable[87] do begin
  386.                         symbol := 'getnumber   ';
  387.                         tType := FunctionT;
  388.                         cType := GetNumC;
  389.                     end;
  390.                 with SymbolTable[88] do begin
  391.                         symbol := 'nop         ';
  392.                         cType := NopC;
  393.                     end;
  394.                 with SymbolTable[89] do begin
  395.                         symbol := 'random      ';
  396.                         tType := FunctionT;
  397.                         cType := RandomC;
  398.                     end;
  399.                 with SymbolTable[90] do begin
  400.                         symbol := 'makeovalroi ';
  401.                         cType := MakeOvalC;
  402.                     end;
  403.                 with SymbolTable[91] do begin
  404.                         symbol := 'drawscale   ';
  405.                         cType := DrawScaleC;
  406.                     end;
  407.                 with SymbolTable[92] do begin
  408.                         symbol := 'setpalette  ';
  409.                         cType := SetPaletteC;
  410.                     end;
  411.                 with SymbolTable[93] do begin
  412.                         symbol := 'makenewwindo';
  413.                         cType := MakeNewC;
  414.                     end;
  415.                 with SymbolTable[94] do begin
  416.                         symbol := 'getpixel    ';
  417.                         tType := FunctionT;
  418.                         cType := GetPixelC;
  419.                     end;
  420.                 with SymbolTable[95] do begin
  421.                         symbol := 'button      ';
  422.                         tType := FunctionT;
  423.                         cType := ButtonC;
  424.                     end;
  425.                 with SymbolTable[96] do begin
  426.                         symbol := 'odd         ';
  427.                         tType := FunctionT;
  428.                         cType := oddC;
  429.                     end;
  430.                 with SymbolTable[97] do begin
  431.                         symbol := 'abs         ';
  432.                         tType := FunctionT;
  433.                         cType := absC;
  434.                     end;
  435.                 with SymbolTable[98] do begin
  436.                         symbol := 'sqrt        ';
  437.                         tType := FunctionT;
  438.                         cType := sqrtC;
  439.                     end;
  440.                 with SymbolTable[99] do begin
  441.                         symbol := 'sin         ';
  442.                         tType := FunctionT;
  443.                         cType := sinC;
  444.                     end;
  445.                 with SymbolTable[100] do begin
  446.                         symbol := 'cos         ';
  447.                         tType := FunctionT;
  448.                         cType := cosC;
  449.                     end;
  450.                 with SymbolTable[101] do begin
  451.                         symbol := 'exp         ';
  452.                         tType := FunctionT;
  453.                         cType := expC;
  454.                     end;
  455.                 with SymbolTable[102] do begin
  456.                         symbol := 'ln          ';
  457.                         tType := FunctionT;
  458.                         cType := lnC;
  459.                     end;
  460.                 with SymbolTable[103] do begin
  461.                         symbol := 'arctan      ';
  462.                         tType := FunctionT;
  463.                         cType := arctanC;
  464.                     end;
  465.                 with SymbolTable[104] do begin
  466.                         symbol := 'sqr         ';
  467.                         tType := FunctionT;
  468.                         cType := sqrC;
  469.                     end;
  470.                 with SymbolTable[105] do begin
  471.                         symbol := 'macro       ';
  472.                         tType := MacroT;
  473.                     end;
  474.                 with SymbolTable[106] do begin
  475.                         symbol := 'procedure   ';
  476.                         tType := ProcIdT;
  477.                     end;
  478.                 with SymbolTable[107] do begin
  479.                         symbol := 'open        ';
  480.                         cType := openC;
  481.                     end;
  482.                 with SymbolTable[108] do begin
  483.                         symbol := 'setimport   ';
  484.                         cType := SetImportC;
  485.                     end;
  486.                 with SymbolTable[109] do begin
  487.                         symbol := 'import      ';
  488.                         cType := ImportC;
  489.                     end;
  490.                 with SymbolTable[110] do begin
  491.                         symbol := 'setimportmin';
  492.                         cType := SetMinMaxC;
  493.                     end;
  494.                 with SymbolTable[111] do begin
  495.                         symbol := 'setcustom   ';
  496.                         cType := SetCustomC;
  497.                     end;
  498.                 with SymbolTable[112] do begin
  499.                         symbol := 'npics       ';
  500.                         tType := FunctionT;
  501.                         cType := nPicsC;
  502.                     end;
  503.                 with SymbolTable[113] do begin
  504.                         symbol := 'selectpic   ';
  505.                         cType := SelectPicC;
  506.                     end;
  507.                 with SymbolTable[114] do begin
  508.                         symbol := 'setpicname  ';
  509.                         cType := SetPicNameC;
  510.                     end;
  511.                 with SymbolTable[115] do begin
  512.                         symbol := 'applylut    ';
  513.                         cType := ApplyLutC;
  514.                     end;
  515.                 with SymbolTable[116] do begin
  516.                         symbol := 'multiplybyco';
  517.                         cType := MulConstC;
  518.                     end;
  519.                 with SymbolTable[117] do begin
  520.                         symbol := 'setnewsize  ';
  521.                         cType := SetSizeC;
  522.                     end;
  523.                 with SymbolTable[118] do begin
  524.                         symbol := 'save        ';
  525.                         cType := SaveC;
  526.                     end;
  527.                 with SymbolTable[119] do begin
  528.                         symbol := 'saveall     ';
  529.                         cType := SaveAllC;
  530.                     end;
  531.                 with SymbolTable[120] do begin
  532.                         symbol := 'saveas      ';
  533.                         cType := SaveAsC;
  534.                     end;
  535.                 with SymbolTable[121] do begin
  536.                         symbol := 'copyresults ';
  537.                         cType := CopyResultsC;
  538.                     end;
  539.                 with SymbolTable[122] do begin
  540.                         symbol := 'boolean     ';
  541.                         tType := BooleanT;
  542.                     end;
  543.                 with SymbolTable[123] do begin
  544.                         symbol := 'true        ';
  545.                         tType := TrueT;
  546.                     end;
  547.                 with SymbolTable[124] do begin
  548.                         symbol := 'false       ';
  549.                         tType := FalseT;
  550.                     end;
  551.                 with SymbolTable[125] do begin
  552.                         symbol := 'close       ';
  553.                         cType := CloseC;
  554.                     end;
  555.                 with SymbolTable[126] do begin
  556.                         symbol := 'dispose     ';
  557.                         cType := DisposeC;
  558.                     end;
  559.                 with SymbolTable[127] do begin
  560.                         symbol := 'disposeall  ';
  561.                         cType := DisposeAllC;
  562.                     end;
  563.                 with SymbolTable[128] do begin
  564.                         symbol := 'duplicate   ';
  565.                         cType := DupC;
  566.                     end;
  567.                 with SymbolTable[129] do begin
  568.                         symbol := 'getinfo     ';
  569.                         cType := GetInfoC;
  570.                     end;
  571.                 with SymbolTable[130] do begin
  572.                         symbol := 'print       ';
  573.                         cType := PrintC;
  574.                     end;
  575.                 with SymbolTable[131] do begin
  576.                         symbol := 'lineto      ';
  577.                         cType := LineToC;
  578.                     end;
  579.                 with SymbolTable[132] do begin
  580.                         symbol := 'setplotlabel';
  581.                         cType := SetLabelsC;
  582.                     end;
  583.                 with SymbolTable[133] do begin
  584.                         symbol := 'setplotscale';
  585.                         cType := SetPlotScaleC;
  586.                     end;
  587.                 with SymbolTable[134] do begin
  588.                         symbol := 'setplotsize ';
  589.                         cType := SetDimC;
  590.                     end;
  591.                 with SymbolTable[135] do begin
  592.                         symbol := 'setscaling  ';
  593.                         cType := ScalingOptionsC;
  594.                     end;
  595.                 with SymbolTable[136] do begin
  596.                         symbol := 'columnaverag';
  597.                         cType := ColumnC;
  598.                     end;
  599.                 with SymbolTable[137] do begin
  600.                         symbol := 'setchannel  ';
  601.                         cType := ChannelC;
  602.                     end;
  603.                 with SymbolTable[138] do begin
  604.                         symbol := 'showpastecon';
  605.                         cType := ShowPasteC;
  606.                     end;
  607.                 with SymbolTable[139] do begin
  608.                         symbol := 'setoption   ';
  609.                         cType := SetOptionC;
  610.                     end;
  611.                 with SymbolTable[140] do begin
  612.                         symbol := 'doand       ';
  613.                         cType := AndC;
  614.                     end;
  615.                 with SymbolTable[141] do begin
  616.                         symbol := 'door        ';
  617.                         cType := OrC;
  618.                     end;
  619.                 with SymbolTable[142] do begin
  620.                         symbol := 'doxor       ';
  621.                         cType := XorC;
  622.                     end;
  623.                 with SymbolTable[143] do begin
  624.                         symbol := 'doblend     ';
  625.                         cType := BlendC;
  626.                     end;
  627.                 with SymbolTable[144] do begin
  628.                         symbol := 'doreplace   ';
  629.                         cType := ReplaceC;
  630.                     end;
  631.                 with SymbolTable[145] do begin
  632.                         symbol := 'add         ';
  633.                         cType := AddC;
  634.                     end;
  635.                 with SymbolTable[146] do begin
  636.                         symbol := 'subtract    ';
  637.                         cType := SubC;
  638.                     end;
  639.                 with SymbolTable[147] do begin
  640.                         symbol := 'setlinewidth';
  641.                         cType := SetWidthC;
  642.                     end;
  643.                 with SymbolTable[148] do begin
  644.                         symbol := 'showresults ';
  645.                         cType := ShowResultsC;
  646.                     end;
  647.                 with SymbolTable[149] do begin
  648.                         symbol := 'startcapturi';
  649.                         cType := StartC;
  650.                     end;
  651.                 with SymbolTable[150] do begin
  652.                         symbol := 'getrow      ';
  653.                         cType := GetRowC;
  654.                     end;
  655.                 with SymbolTable[151] do begin
  656.                         symbol := 'putrow      ';
  657.                         cType := PutRowC;
  658.                     end;
  659.                 with SymbolTable[152] do begin
  660.                         symbol := 'getcolumn   ';
  661.                         cType := GetColumnC;
  662.                     end;
  663.                 with SymbolTable[153] do begin
  664.                         symbol := 'putcolumn   ';
  665.                         cType := PutColumnC;
  666.                     end;
  667.                 with SymbolTable[154] do begin
  668.                         symbol := 'allsamesize ';
  669.                         tType := FunctionT;
  670.                         cType := SameSizeC;
  671.                     end;
  672.                 with SymbolTable[155] do begin
  673.                         symbol := 'cvalue      ';
  674.                         tType := FunctionT;
  675.                         cType := cValueC;
  676.                     end;
  677.                 with SymbolTable[156] do begin
  678.                         symbol := 'plotxyz     ';
  679.                         cType := PlotXYZC;
  680.                     end;
  681.                 with SymbolTable[157] do begin
  682.                         symbol := 'includeinter';
  683.                         cType := IncludeC;
  684.                     end;
  685.                 with SymbolTable[158] do begin
  686.                         symbol := 'wandautomeas';
  687.                         cType := AutoC;
  688.                     end;
  689.                 with SymbolTable[159] do begin
  690.                         symbol := 'labelparticl';
  691.                         cType := LabelC;
  692.                     end;
  693.                 with SymbolTable[160] do begin
  694.                         symbol := 'outlineparti';
  695.                         cType := OutlineParticlesC;
  696.                     end;
  697.                 with SymbolTable[161] do begin
  698.                         symbol := 'ignorepartic';
  699.                         cType := IgnoreC;
  700.                     end;
  701.                 with SymbolTable[162] do begin
  702.                         symbol := 'adjustareas ';
  703.                         cType := AdjustC;
  704.                     end;
  705.                 with SymbolTable[163] do begin
  706.                         symbol := 'setparticles';
  707.                         cType := SetParticleSizeC;
  708.                     end;
  709.                 with SymbolTable[164] do begin
  710.                         symbol := 'setprecision';
  711.                         cType := SetPrecisionC;
  712.                     end;
  713.                 with SymbolTable[165] do begin
  714.                         symbol := 'imagemath   ';
  715.                         cType := ImageMathC;
  716.                     end;
  717.                 with SymbolTable[166] do begin
  718.                         symbol := 'pastelive   ';
  719.                         cType := PasteLiveC;
  720.                     end;
  721.                 with SymbolTable[167] do begin
  722.                         symbol := 'pidexists   ';
  723.                         tType := FunctionT;
  724.                         cType := PidExistsC;
  725.                     end;
  726.                 with SymbolTable[168] do begin
  727.                         symbol := 'pos         ';
  728.                         tType := FunctionT;
  729.                         cType := PosC;
  730.                     end;
  731.                 with SymbolTable[169] do begin
  732.                         symbol := 'delete      ';
  733.                         cType := DeleteC;
  734.                     end;
  735.                 with SymbolTable[170] do begin
  736.                         symbol := 'length      ';
  737.                         tType := FunctionT;
  738.                         cType := LengthC;
  739.                     end;
  740.                 with SymbolTable[171] do begin
  741.                         symbol := 'getscale    ';
  742.                         cType := GetScaleC;
  743.                     end;
  744.                 with SymbolTable[172] do begin
  745.                         symbol := 'autooutline ';
  746.                         cType := AutoOutlineC;
  747.                     end;
  748.                 with SymbolTable[173] do begin
  749.                         symbol := 'filter      ';
  750.                         cType := FilterC;
  751.                     end;
  752.                 with SymbolTable[174] do begin
  753.                         symbol := 'setsaveas   ';
  754.                         cType := SetSaveAsC;
  755.                     end;
  756.                 with SymbolTable[175] do begin
  757.                         symbol := 'putpixel    ';
  758.                         cType := PutPixelC;
  759.                     end;
  760.                 with SymbolTable[176] do begin
  761.                         symbol := 'choosepic   ';
  762.                         cType := ChoosePicC;
  763.                     end;
  764.                 with SymbolTable[177] do begin
  765.                         symbol := 'write       ';
  766.                         cType := WriteC;
  767.                     end;
  768.                 with SymbolTable[178] do begin
  769.                         symbol := 'writeln     ';
  770.                         cType := WritelnC;
  771.                     end;
  772.                 with SymbolTable[179] do begin
  773.                         symbol := 'scaleselecti';
  774.                         cType := ScaleSelectionC;
  775.                     end;
  776.                 with SymbolTable[180] do begin
  777.                         symbol := 'picnumber   ';
  778.                         tType := FunctionT;
  779.                         cType := PicNumC;
  780.                     end;
  781.                 with SymbolTable[181] do begin
  782.                         symbol := 'export      ';
  783.                         cType := ExportC;
  784.                     end;
  785.                 with SymbolTable[182] do begin
  786.                         symbol := 'reducenoise ';
  787.                         cType := ReduceC;
  788.                     end;
  789.                 with SymbolTable[183] do begin
  790.                         symbol := 'changevalues';
  791.                         cType := ChangeC;
  792.                     end;
  793.                 with SymbolTable[184] do begin
  794.                         symbol := 'histogram   ';
  795.                         tType := ArrayT;
  796.                         cType := CommandType(HistogramA);
  797.                     end;
  798.                 with SymbolTable[185] do begin
  799.                         symbol := 'scaleconvolu';
  800.                         cType := ScaleConvolutionsC;
  801.                     end;
  802.                 with SymbolTable[186] do begin
  803.                         symbol := 'rarea       ';
  804.                         tType := ArrayT;
  805.                         cType := CommandTYpe(rAreaA);
  806.                     end;
  807.                 with SymbolTable[187] do begin
  808.                         symbol := 'rmean       ';
  809.                         tType := ArrayT;
  810.                         cType := CommandType(rMeanA);
  811.                     end;
  812.                 with SymbolTable[188] do begin
  813.                         symbol := 'rx          ';
  814.                         tType := ArrayT;
  815.                         cType := CommandType(rXA);
  816.                     end;
  817.                 with SymbolTable[189] do begin
  818.                         symbol := 'ry          ';
  819.                         tType := ArrayT;
  820.                         cType := CommandType(rYA);
  821.                     end;
  822.                 with SymbolTable[190] do begin
  823.                         symbol := 'rmin        ';
  824.                         tType := ArrayT;
  825.                         cType := CommandTYpe(rMinA);
  826.                     end;
  827.                 with SymbolTable[191] do begin
  828.                         symbol := 'rmax        ';
  829.                         tType := ArrayT;
  830.                         cType := CommandType(rMaxA);
  831.                     end;
  832.                 with SymbolTable[192] do begin
  833.                         symbol := 'rcount      ';
  834.                         tType := FunctionT;
  835.                         cType := rCountC;
  836.                     end;
  837.                 with SymbolTable[193] do begin
  838.                         symbol := 'updateresult';
  839.                         cType := UpdateResultsC;
  840.                     end;
  841.                 with SymbolTable[194] do begin
  842.                         symbol := 'stopcapturin';
  843.                         cType := StopC;
  844.                     end;
  845.                 with SymbolTable[195] do begin
  846.                         symbol := 'tilewindows ';
  847.                         cType := TileC;
  848.                     end;
  849.                 with SymbolTable[196] do begin
  850.                         symbol := 'rlength     ';
  851.                         tType := ArrayT;
  852.                         cType := CommandType(rLengthA);
  853.                     end;
  854.                 with SymbolTable[197] do begin
  855.                         symbol := 'rmajor      ';
  856.                         tType := ArrayT;
  857.                         cType := CommandType(rMajorA);
  858.                     end;
  859.                 with SymbolTable[198] do begin
  860.                         symbol := 'rminor      ';
  861.                         tType := ArrayT;
  862.                         cType := CommandType(rMinorA);
  863.                     end;
  864.                 with SymbolTable[199] do begin
  865.                         symbol := 'rangle      ';
  866.                         tType := ArrayT;
  867.                         cType := CommandType(rAngleA);
  868.                     end;
  869.                 with SymbolTable[200] do begin
  870.                         symbol := 'setmajorlabe';
  871.                         cType := SetMajorC;
  872.                     end;
  873.                 with SymbolTable[201] do begin
  874.                         symbol := 'setminorlabe';
  875.                         cType := SetMinorC;
  876.                     end;
  877.                 with SymbolTable[202] do begin
  878.                         symbol := 'getmouse    ';
  879.                         cType := GetMouseC;
  880.                     end;
  881.                 with SymbolTable[203] do begin
  882.                         symbol := 'slicenumber ';
  883.                         tType := FunctionT;
  884.                         cType := GetSliceC;
  885.                     end;
  886.                 with SymbolTable[204] do begin
  887.                         symbol := 'nslices     ';
  888.                         tType := FunctionT;
  889.                         cType := nSlicesC;
  890.                     end;
  891.                 with SymbolTable[205] do begin
  892.                         symbol := 'selectslice ';
  893.                         cType := SelectSliceC;
  894.                     end;
  895.                 with SymbolTable[206] do begin
  896.                         symbol := 'addslice    ';
  897.                         cType := AddSliceC;
  898.                     end;
  899.                 with SymbolTable[207] do begin
  900.                         symbol := 'deleteslice ';
  901.                         cType := DeleteSliceC;
  902.                     end;
  903.                 with SymbolTable[208] do begin
  904.                         symbol := 'makenewstack';
  905.                         cType := MakeStackC;
  906.                     end;
  907.                 with SymbolTable[209] do begin
  908.                         symbol := 'averageframe';
  909.                         cType := AverageFramesC;
  910.                     end;
  911.                 with SymbolTable[210] do begin
  912.                         symbol := 'waitfortrigg';
  913.                         cType := TriggerC;
  914.                     end;
  915.                 with SymbolTable[211] do begin
  916.                         symbol := 'docopy      ';
  917.                         cType := CopyModeC;
  918.                     end;
  919.                 with SymbolTable[212] do begin
  920.                         symbol := 'reslice     ';
  921.                         cType := ResliceC;
  922.                     end;
  923.                 with SymbolTable[213] do begin
  924.                         symbol := 'makelineroi ';
  925.                         cType := MakeLineC;
  926.                     end;
  927.                 with SymbolTable[214] do begin
  928.                         symbol := 'plotprofile ';
  929.                         cType := PlotProfileC;
  930.                     end;
  931.                 with SymbolTable[215] do begin
  932.                         symbol := 'gettime     ';
  933.                         cType := GetTimeC;
  934.                     end;
  935.                 with SymbolTable[216] do begin
  936.                         symbol := 'setscale    ';
  937.                         cType := SetScaleC;
  938.                     end;
  939.                 with SymbolTable[217] do begin
  940.                         symbol := 'savestate   ';
  941.                         cType := SaveStateC;
  942.                     end;
  943.                 with SymbolTable[218] do begin
  944.                         symbol := 'restorestate';
  945.                         cType := RestoreStateC;
  946.                     end;
  947.                 with SymbolTable[219] do begin
  948.                         symbol := 'setcounter  ';
  949.                         cType := SetCounterC;
  950.                     end;
  951.                 with SymbolTable[220] do begin
  952.                         symbol := 'redlut      ';
  953.                         tType := ArrayT;
  954.                         cType := CommandType(RedLutA);
  955.                     end;
  956.                 with SymbolTable[221] do begin
  957.                         symbol := 'greenlut    ';
  958.                         tType := ArrayT;
  959.                         cType := CommandType(GreenLutA);
  960.                     end;
  961.                 with SymbolTable[222] do begin
  962.                         symbol := 'bluelut     ';
  963.                         tType := ArrayT;
  964.                         cType := CommandType(BlueLutA);
  965.                     end;
  966.                 with SymbolTable[223] do begin
  967.                         symbol := 'updatelut   ';
  968.                         cType := UpdateLutC;
  969.                     end;
  970.                 with SymbolTable[224] do begin
  971.                         symbol := 'showmessage ';
  972.                         cType := ShowMsgC;
  973.                     end;
  974.                 with SymbolTable[225] do begin
  975.                         symbol := 'setbinarycou';
  976.                         cType := SetCountC;
  977.                     end;
  978.                 with SymbolTable[226] do begin
  979.                         symbol := 'rstddev     ';
  980.                         tType := ArrayT;
  981.                         cType := CommandType(rStdDevA);
  982.                     end;
  983.                 with SymbolTable[227] do begin
  984.                         symbol := 'propagatelut';
  985.                         cType := PropagateLutC;
  986.                     end;
  987.                 with SymbolTable[228] do begin
  988.                         symbol := 'chooseslice ';
  989.                         cType := ChooseSliceC;
  990.                     end;
  991.                 with SymbolTable[229] do begin
  992.                         symbol := 'setslicespac';
  993.                         cType := SetSpacingC;
  994.                     end;
  995.                 with SymbolTable[230] do begin
  996.                         symbol := 'getslicespac';
  997.                         tType := FunctionT;
  998.                         cType := GetSpacingC;
  999.                     end;
  1000.                 with SymbolTable[231] do begin
  1001.                         symbol := 'linebuffer  ';
  1002.                         tType := ArrayT;
  1003.                         cType := CommandType(BufferA);
  1004.                     end;
  1005.                 with SymbolTable[232] do begin
  1006.                         symbol := 'ruser1      ';
  1007.                         tType := ArrayT;
  1008.                         cType := CommandType(rUser1A);
  1009.                     end;
  1010.                 with SymbolTable[233] do begin
  1011.                         symbol := 'ruser2      ';
  1012.                         tType := ArrayT;
  1013.                         cType := CommandType(rUser2A);
  1014.                     end;
  1015.                 with SymbolTable[234] do begin
  1016.                         symbol := 'propagateden';
  1017.                         cType := PropagateDensityC;
  1018.                     end;
  1019.                 with SymbolTable[235] do begin
  1020.                         symbol := 'propagatespa';
  1021.                         cType := PropagateSpatialC;
  1022.                     end;
  1023.                 with SymbolTable[236] do begin
  1024.                         symbol := 'setoptions  ';
  1025.                         cType := SetOptionsC;
  1026.                     end;
  1027.                 with SymbolTable[237] do begin
  1028.                         symbol := 'requiresvers';
  1029.                         cType := RequiresC;
  1030.                     end;
  1031.                 with SymbolTable[238] do begin
  1032.                         symbol := 'getplotdata ';
  1033.                         cType := GetPlotDataC;
  1034.                     end;
  1035.                 with SymbolTable[239] do begin
  1036.                         symbol := 'plotdata    ';
  1037.                         tType := ArrayT;
  1038.                         cType := CommandType(PlotDataA);
  1039.                     end;
  1040.                 with SymbolTable[240] do begin
  1041.                         symbol := 'setuser1labe';
  1042.                         cType := SetUser1C;
  1043.                     end;
  1044.                 with SymbolTable[241] do begin
  1045.                         symbol := 'setuser2labe';
  1046.                         cType := SetUser2C;
  1047.                     end;
  1048.                 with SymbolTable[242] do begin
  1049.                         symbol := 'subtractback';
  1050.                         cType := SubtractBackgroundC;
  1051.                     end;
  1052.                 with SymbolTable[243] do begin
  1053.                         symbol := 'autothreshol';
  1054.                         cType := AutoThresholdC;
  1055.                     end;
  1056.                 with SymbolTable[244] do begin
  1057.                         symbol := 'setexport   ';
  1058.                         cType := SetExportC;
  1059.                     end;
  1060.                 with SymbolTable[245] do begin
  1061.                         symbol := 'movewindow  ';
  1062.                         cType := MoveWindowC;
  1063.                     end;
  1064.                 with SymbolTable[246] do begin
  1065.                         symbol := 'usercode    ';
  1066.                         cType := UserCodeC;
  1067.                     end;
  1068.                 with SymbolTable[247] do begin
  1069.                         symbol := 'invertlut   ';
  1070.                         cType := InvertLutC;
  1071.                     end;
  1072.                 with SymbolTable[248] do begin
  1073.                         symbol := 'xcoordinates';
  1074.                         tType := ArrayT;
  1075.                         cType := CommandType(xCoordinatesA);
  1076.                     end;
  1077.                 with SymbolTable[249] do begin
  1078.                         symbol := 'ycoordinates';
  1079.                         tType := ArrayT;
  1080.                         cType := CommandType(yCoordinatesA);
  1081.                     end;
  1082.                 with SymbolTable[250] do begin
  1083.                         symbol := 'ncoordinates';
  1084.                         tType := FunctionT;
  1085.                         cType := nCoordinatesC;
  1086.                     end;
  1087.                 with SymbolTable[251] do begin
  1088.                         symbol := 'string      ';
  1089.                         tType := StringT;
  1090.                     end;
  1091.                 with SymbolTable[252] do begin
  1092.                         symbol := 'getstring   ';
  1093.                         tType := StringFunctionT;
  1094.                         cType := GetStringC;
  1095.                     end;
  1096.                 with SymbolTable[253] do begin
  1097.                         symbol := 'openserial  ';
  1098.                         cType := OpenSerialC;
  1099.                     end;
  1100.                 with SymbolTable[254] do begin
  1101.                         symbol := 'getserial   ';
  1102.                         tType := StringFunctionT;
  1103.                         cType := GetSerialC;
  1104.                     end;
  1105.                 with SymbolTable[255] do begin
  1106.                         symbol := 'putserial   ';
  1107.                         cType := PutSerialC;
  1108.                     end;
  1109.                 with SymbolTable[256] do begin
  1110.                         symbol := 'chr         ';
  1111.                         tType := StringFunctionT;
  1112.                         cType := ChrC;
  1113.                     end;
  1114.                 with SymbolTable[257] do begin
  1115.                         symbol := 'ord         ';
  1116.                         tType := FunctionT;
  1117.                         cType := OrdC;
  1118.                     end;
  1119.                 with SymbolTable[258] do begin
  1120.                         symbol := 'setcursor   ';
  1121.                         cType := SetCursorC;
  1122.                     end;
  1123.                 with SymbolTable[259] do begin
  1124.                         symbol := 'tickcount   ';
  1125.                         tType := FunctionT;
  1126.                         cType := TickCountC;
  1127.                     end;
  1128.                 with SymbolTable[260] do begin
  1129.                         symbol := 'concat      ';
  1130.                         tType := StringFunctionT;
  1131.                         cType := ConcatC;
  1132.                     end;
  1133.                 with SymbolTable[261] do begin
  1134.                         symbol := 'setvideo    ';
  1135.                         cType := SetVideoC;
  1136.                     end;
  1137.                 with SymbolTable[262] do begin
  1138.                         symbol := 'stringtonum ';
  1139.                         tType := FunctionT;
  1140.                         cType := StringToNumC;
  1141.                     end;
  1142.                 with SymbolTable[263] do begin
  1143.                         symbol := 'acquire     ';
  1144.                         cType := AcquireC;
  1145.                     end;
  1146.                 with SymbolTable[264] do begin
  1147.                         symbol := 'undobuffersi';
  1148.                         tType := FunctionT;
  1149.                         cType := UndoSizeC;
  1150.                     end;
  1151.                 with SymbolTable[265] do begin
  1152.                         symbol := 'scion       ';
  1153.                         tType := ArrayT;
  1154.                         cType := CommandType(ScionA);
  1155.                     end;
  1156.                 with SymbolTable[266] do begin
  1157.                         symbol := 'callfilter  ';
  1158.                         cType := CallFilterC;
  1159.                     end;
  1160.                 with SymbolTable[267] do begin
  1161.                         symbol := 'photomode   ';
  1162.                         cType := PhotoModeC;
  1163.                     end;
  1164.                 with SymbolTable[268] do begin
  1165.                         symbol := 'rgbtoindexed';
  1166.                         cType := RGBToIndexedC;
  1167.                     end;
  1168.                 with SymbolTable[269] do begin
  1169.                         symbol := 'surfaceplot ';
  1170.                         cType := SurfacePlotC;
  1171.                     end;
  1172.                 with SymbolTable[270] do begin
  1173.                         symbol := 'selectwindow';
  1174.                         cType := SelectWindowC;
  1175.                     end;
  1176.                 with SymbolTable[271] do begin
  1177.                         symbol := 'newtextwindo';
  1178.                         cType := NewTextWindowC;
  1179.                     end;
  1180.                 with SymbolTable[272] do begin
  1181.                         symbol := 'capturecolor';
  1182.                         cType := CaptureColorC;
  1183.                     end;
  1184.                 with SymbolTable[273] do begin
  1185.                         symbol := 'getthreshold';
  1186.                         cType := GetThresholdC;
  1187.                     end;
  1188.                 with SymbolTable[274] do begin
  1189.                         symbol := 'averageslice';
  1190.                         cType := AverageSlicesC;
  1191.                     end;
  1192.                 with SymbolTable[275] do begin
  1193.                         symbol := 'bitand      ';
  1194.                         tType := FunctionT;
  1195.                         cType := BitAndC;
  1196.                     end;
  1197.                 with SymbolTable[276] do begin
  1198.                         symbol := 'bitor       ';
  1199.                         tType := FunctionT;
  1200.                         cType := BitOrC;
  1201.                     end;
  1202.                 with SymbolTable[277] do begin
  1203.                         symbol := 'sortpalette ';
  1204.                         cType := SortPaletteC;
  1205.                     end;
  1206.                 with SymbolTable[278] do begin
  1207.                         symbol := 'pidnumber   ';
  1208.                         tType := FunctionT;
  1209.                         cType := PidNumC;
  1210.                     end;
  1211.                 with SymbolTable[279] do begin
  1212.                         symbol := 'project     ';
  1213.                         cType := ProjectC;
  1214.                     end;
  1215.                 with SymbolTable[280] do begin
  1216.                         symbol := 'windowtitle ';
  1217.                         tType := StringFunctionT;
  1218.                         cType := WindowTitleC;
  1219.                     end;
  1220.                 with SymbolTable[281] do begin
  1221.                         symbol := 'calibrate   ';
  1222.                         cType := CalibrateC;
  1223.                     end;
  1224.                 with SymbolTable[282] do begin
  1225.                         symbol := 'callexport  ';
  1226.                         cType := CallExportC;
  1227.                     end;
  1228.                 with SymbolTable[283] do begin
  1229.                         symbol := 'keydown     ';
  1230.                         tType := FunctionT;
  1231.                         cType := KeyDownC;
  1232.                     end;
  1233.                 with SymbolTable[284] do begin
  1234.                         symbol := 'indexedtorgb';
  1235.                         cType := IndexedToRgbC;
  1236.                     end;
  1237.                 with SymbolTable[285] do begin
  1238.                         symbol := 'makemovie   ';
  1239.                         cType := MakeMovieC;
  1240.                     end;
  1241.                 with SymbolTable[286] do begin
  1242.                   symbol := 'setprojectio';
  1243.                   cType := SetProjectionC;
  1244.                  end;
  1245.                 with SymbolTable[287] do begin
  1246.                   symbol := 'gethistogram';
  1247.                   cType := GetHistogramC;
  1248.                  end;
  1249.                 with SymbolTable[288] do begin
  1250.                         symbol := 'get         ';
  1251.                         tType := FunctionT;
  1252.                         cType := GetC;
  1253.                     end;
  1254.                 with SymbolTable[289] do begin
  1255.                         symbol := 'fft         ';
  1256.                         cType := fftC;
  1257.                     end;
  1258.                 with SymbolTable[290] do begin
  1259.                         symbol := 'function    ';
  1260.                         tType := UserFuncIDT;
  1261.                     end;
  1262.                 with SymbolTable[291] do begin
  1263.                         symbol := 'getpath     ';
  1264.                         tType := StringFunctionT;
  1265.                         cType := GetPathC;
  1266.                     end;
  1267.                 with SymbolTable[292] do begin
  1268.                         symbol := 'getfileinfo ';
  1269.                         cType := GetFileInfoC;
  1270.                     end;
  1271.                 with SymbolTable[293] do begin
  1272.                         symbol := 'selecttool  ';
  1273.                         cType := SelectToolC;
  1274.                     end;
  1275.                 with SymbolTable[294] do begin
  1276.                         symbol := 'binary      ';
  1277.                         cType := BinaryC;
  1278.                     end;
  1279.             end; {with}
  1280.         nSymbols := 294; {Must be subscript of last predefined symbol}
  1281.     end;
  1282.  
  1283.  
  1284.     procedure DeallocateStrings2 (first, last: integer);
  1285.         var
  1286.             i: integer;
  1287.     begin
  1288.         with MacrosP^ do begin
  1289.                 for i := first to last do begin
  1290.                         if Stack[i].StringH <> nil then begin
  1291.                                 DisposeHandle(handle(Stack[i].StringH));
  1292.                                 Stack[i].StringH := nil;
  1293.                             end;
  1294.                     end;
  1295.             end;
  1296.     end;
  1297.  
  1298.  
  1299.     function CurrentLine: str255;
  1300.         var
  1301.             cLine: str255;
  1302.             i, count: integer;
  1303.     begin
  1304.         i := StartOfLine;
  1305.         if (i < 0) or (i > EndMacros) then begin
  1306.                 CurrentLine := '';
  1307.                 exit(CurrentLine);
  1308.             end;
  1309.         cLine := '';
  1310.         count := 0;
  1311.         repeat
  1312.             i := i + 1;
  1313.             count := count + 1;
  1314.             if not (MacroBufP^[i] = cr) or (MacroBufP^[i] = '|') then
  1315.                 cLine := concat(cLine, MacroBufP^[i]);
  1316.         until (i >= EndMacros) or (MacroBufP^[i] = cr) or (MacroBufP^[i] = '|') or (count > 60);
  1317.         while (length(cLine) > 1) and (cLine[1] = ' ') do
  1318.             delete(cLine, 1, 1);
  1319.         CurrentLine := concat(crStr, '<<', cLine, '>>');
  1320.     end;
  1321.  
  1322.  
  1323.     procedure LTMacroError (str: str255);
  1324.   {Report load-time errors}
  1325.         var
  1326.             str2: str255;
  1327.             i, count: integer;
  1328.             line: string;
  1329.     begin
  1330.         if token = DoneT then
  1331.             exit(LTMacroError);
  1332.         if TopOfStack > 0 then
  1333.             DeallocateStrings2(1, TopOfStack);
  1334.         PutError(concat(str, ' in line ', long2str(MacroLineNumber), ' of macro file.', CurrentLine));
  1335.         Token := DoneT;
  1336.     end;
  1337.  
  1338.  
  1339.     procedure LookupIdentifier;
  1340.         var
  1341.             i: integer;
  1342.     begin
  1343.         with MacrosP^ do
  1344.             for i := 1 to nSymbols do begin
  1345.                     if TokenSymbol = SymbolTable[i].symbol then
  1346.                         with SymbolTable[i] do begin
  1347.                                 token := tType;
  1348.                                 MacroCommand := cType;
  1349.                                 TokenLoc := loc;
  1350.                                 SymbolTableLoc := i;
  1351.                                 exit(LookupIdentifier);
  1352.                             end;
  1353.                 end; {for}
  1354.         token := UnknownIdentifier;
  1355.     end;
  1356.  
  1357.  
  1358.     procedure GetToken;
  1359.         var
  1360.             c: char;
  1361.             SymbolLength: integer;
  1362.     begin
  1363.         if token = DoneT then
  1364.             exit(GetToken);
  1365.         SavePC := PC;
  1366.         SaveToken := token;
  1367.         while not (MacroBufP^[pc] in ['a'..'z', '0'..'9', '(', ')', ',', '''', '+', '-', '*', '/', ':', ';', '=', '.', '>', '<', '[', ']', '|']) do begin  {skip white space}
  1368.                 if MacroBufP^[pc] = cr then
  1369.                     MacroBufP^[pc] := '|'
  1370.                 else
  1371.                     pc := pc + 1;
  1372.                 if pc > EndMacros then begin
  1373.                         Token := DoneT;
  1374.                         exit(GetToken);
  1375.                     end;
  1376.             end;
  1377.         c := MacroBufP^[pc];
  1378.         case c of
  1379.             'a'..'z':  begin
  1380.                     TokenSymbol := BlankSymbol;
  1381.                     SymbolLength := 0;
  1382.                     while MacroBufP^[pc] in ['a'..'z', '0'..'9'] do begin
  1383.                             SymbolLength := SymbolLength + 1;
  1384.                             if SymbolLength <= SymbolSize then
  1385.                                 TokenSymbol[SymbolLength] := MacroBufP^[pc];
  1386.                             pc := pc + 1;
  1387.                             if pc > EndMacros then begin
  1388.                                     Token := DoneT;
  1389.                                     exit(GetToken);
  1390.                                 end;
  1391.                         end;
  1392.                     Token := identifier;
  1393.                     LookupIdentifier;
  1394.                     exit(GetToken);
  1395.                 end;
  1396.             '0'..'9', '.':  begin
  1397.                     TokenStr := '';
  1398.                     while MacroBufP^[pc] in ['0'..'9', '.'] do begin
  1399.                             TokenStr := Concat(TokenStr, c);
  1400.                             pc := pc + 1;
  1401.                             c := MacroBufP^[pc];
  1402.                             if pc > EndMacros then begin
  1403.                                     Token := DoneT;
  1404.                                     exit(GetToken);
  1405.                                 end;
  1406.                         end;
  1407.                     Token := NumericLiteral;
  1408.                     if MacroBufP^[pc] in ['a'..'z'] then
  1409.                         LTMacroError('Operator or delimiter expected');
  1410.                     exit(GetToken);
  1411.                 end;
  1412.             '(':  begin
  1413.                     Token := LeftParen;
  1414.                     pc := pc + 1;
  1415.                 end;
  1416.             ')':  begin
  1417.                     Token := RightParen;
  1418.                     pc := pc + 1;
  1419.                 end;
  1420.             '[':  begin
  1421.                     Token := LeftBracket;
  1422.                     pc := pc + 1;
  1423.                 end;
  1424.             ']':  begin
  1425.                     Token := RightBracket;
  1426.                     pc := pc + 1;
  1427.                 end;
  1428.             ',':  begin
  1429.                     Token := comma;
  1430.                     pc := pc + 1;
  1431.                 end;
  1432.             ':': 
  1433.                 if MacroBufP^[pc + 1] = '=' then begin
  1434.                         Token := AssignOp;
  1435.                         pc := pc + 2;
  1436.                     end
  1437.                 else begin
  1438.                         Token := colon;
  1439.                         pc := pc + 1;
  1440.                     end;
  1441.             ';':  begin
  1442.                     Token := SemiColon;
  1443.                     pc := pc + 1;
  1444.                 end;
  1445.             '+':  begin
  1446.                     Token := PlusOp;
  1447.                     pc := pc + 1;
  1448.                 end;
  1449.             '-':  begin
  1450.                     Token := MinusOp;
  1451.                     pc := pc + 1;
  1452.                 end;
  1453.             '*':  begin
  1454.                     Token := MulOp;
  1455.                     pc := pc + 1;
  1456.                 end;
  1457.             '/':  begin
  1458.                     Token := DivOp;
  1459.                     pc := pc + 1;
  1460.                 end;
  1461.             '''':  begin
  1462.                     TokenStr := '';
  1463.                     pc := pc + 1;
  1464.                     while MacroBufP^[pc] <> '''' do begin
  1465.                             TokenStr := Concat(TokenStr, MacroBufP^[pc]);
  1466.                             pc := pc + 1;
  1467.                             if pc > EndMacros then begin
  1468.                                     Token := DoneT;
  1469.                                     exit(GetToken);
  1470.                                 end;
  1471.                         end;
  1472.                     pc := pc + 1;
  1473.                     Token := StringLiteral;
  1474.                 end;
  1475.             '=':  begin
  1476.                     Token := eqOp;
  1477.                     pc := pc + 1;
  1478.                 end;
  1479.             '<':  begin
  1480.                     pc := pc + 1;
  1481.                     if MacroBufP^[pc] = '>' then begin
  1482.                             token := neOp;
  1483.                             pc := pc + 1;
  1484.                         end
  1485.                     else if MacroBufP^[pc] = '=' then begin
  1486.                             token := leOp;
  1487.                             pc := pc + 1;
  1488.                         end
  1489.                     else
  1490.                         token := ltOp;
  1491.                 end;
  1492.             '>':  begin
  1493.                     pc := pc + 1;
  1494.                     if MacroBufP^[pc] = '=' then begin
  1495.                             token := geOp;
  1496.                             pc := pc + 1;
  1497.                         end
  1498.                     else
  1499.                         token := gtOp;
  1500.                 end;
  1501.             '|':  begin
  1502.                     Token := NewLineT;
  1503.                     MacroLineNumber := MacroLineNumber + 1;
  1504.                     StartOfLine := pc;
  1505.                     pc := pc + 1;
  1506.                 end;
  1507.             otherwise begin
  1508.                     token := NullT;
  1509.                     beep;
  1510.                 end;
  1511.         end; {case}
  1512.     end;
  1513.  
  1514.  
  1515.     procedure AddProcedure;
  1516.     begin
  1517.         GetToken;
  1518.         if token <> UnknownIdentifier then begin
  1519.                 LTMacroError('Procedure name missing or previously defined');
  1520.                 exit(AddProcedure);
  1521.             end;
  1522.         if nSymbols >= MaxSymbols then begin
  1523.                 LTMacroError('Symbol table overflow');
  1524.                 exit(AddProcedure);
  1525.             end;
  1526.         nSymbols := nSymbols + 1;
  1527.         nProcedures := nProcedures + 1;
  1528.         with MacrosP^, MacrosP^.SymbolTable[nSymbols] do begin
  1529.                 symbol := TokenSymbol;
  1530.                 tType := procedureT;
  1531.                 cType := NullC;
  1532.                 if MacroBufP^[pc] = ';' then
  1533.                     pc := pc + 1;
  1534.                 loc := pc2 + 1;
  1535.             end;
  1536.     end;
  1537.  
  1538.  
  1539.     procedure AddFunction;
  1540.     begin
  1541.         GetToken;
  1542.         if token <> UnknownIdentifier then begin
  1543.                 LTMacroError('Function name missing or previously defined');
  1544.                 exit(AddFunction);
  1545.             end;
  1546.         if nSymbols >= MaxSymbols then begin
  1547.                 LTMacroError('Symbol table overflow');
  1548.                 exit(AddFunction);
  1549.             end;
  1550.         nSymbols := nSymbols + 1;
  1551.         nProcedures := nProcedures + 1;
  1552.         with MacrosP^, MacrosP^.SymbolTable[nSymbols] do begin
  1553.                 symbol := TokenSymbol;
  1554.                 tType := UserFunctionT;
  1555.                 cType := NullC;
  1556.                 loc := pc2 + 1;
  1557.             end;
  1558.     end;
  1559.  
  1560.  
  1561.     procedure AddIdentifier;
  1562.     begin
  1563.         if nSymbols >= MaxSymbols then begin
  1564.                 LTMacroError('Symbol table overflow');
  1565.                 exit(AddIdentifier);
  1566.             end;
  1567.         nSymbols := nSymbols + 1;
  1568.         with MacrosP^, MacrosP^.SymbolTable[nSymbols] do begin
  1569.                 symbol := TokenSymbol;
  1570.                 tType := Identifier;
  1571.                 cType := NullC;
  1572.                 loc := pc2;
  1573.             end;
  1574.     end;
  1575.  
  1576.  
  1577.     procedure GetGDToken;
  1578.     begin
  1579.         GetToken;
  1580.         while token = NewLineT do begin
  1581.             MacrosP^.macros[pc2] := chr(ord(token));
  1582.             pc2 := pc2 + 1;
  1583.             GetToken;
  1584.         end;
  1585.     end;
  1586.  
  1587.  
  1588.     procedure DoGlobalDeclaration;
  1589.         var
  1590.             SaveStackLoc, StackLoc: integer;
  1591.     begin
  1592.         SaveStackLoc := TopOfStack;
  1593.         while (token = UnknownIdentifier) or (token = Identifier) do begin
  1594.                 if Token = UnknownIdentifier then begin
  1595.                         AddIdentifier;
  1596.                         SymbolTableLoc := nSymbols;
  1597.                         token := identifier;
  1598.                     end;
  1599.                 if TopOfStack >= MaxMacroStackSize then begin
  1600.                         LTMacroError(StackOverflow);
  1601.                         exit(DoGlobalDeclaration);
  1602.                     end;
  1603.                 TopOfStack := TopOfStack + 1;
  1604.                 nGlobals := nGlobals + 1;
  1605.                 with MacrosP^.stack[TopOfStack] do begin
  1606.                         SymbolTableIndex := SymbolTableLoc;
  1607.                         value := 0.0;
  1608.                         StringH := nil;
  1609.                     end;
  1610.                 GetGDToken;
  1611.                 if token = comma then
  1612.                     GetGDToken;
  1613.                 if (token = FunctionT) or (token = StringFunctionT) or (token = CommandT) or (token = ArrayT) then begin
  1614.                         LTMacroError('Predefined identifier');
  1615.                         exit(DoGlobalDeclaration);
  1616.                     end;
  1617.             end; {while}
  1618.         if token <> colon then
  1619.             LTMacroError('":" expected');
  1620.         GetGDToken;
  1621.         if (token <> IntegerT) and (token <> RealT) and (token <> BooleanT) and (token <> StringT) then
  1622.             LTMacroError('"integer", "real", "boolean" or "string" expected');
  1623.         for StackLoc := SaveStackLoc + 1 to TopOfStack do
  1624.             with macrosP^.stack[StackLoc] do
  1625.                 case token of
  1626.                     IntegerT: 
  1627.                         vType := IntVar;
  1628.                     RealT: 
  1629.                         vType := RealVar;
  1630.                     BooleanT: 
  1631.                         vType := BooleanVar;
  1632.                     StringT:  begin
  1633.                             vType := StringVar;
  1634.                             StringH := str255H(NewHandle(SizeOf(str255)));
  1635.                             if StringH = nil then begin
  1636.                                     LTMacroError('Out of memory');
  1637.                                     Token := DoneT
  1638.                                 end
  1639.                             else
  1640.                                 StringH^^ := 'Global String';
  1641.                         end;
  1642.                     otherwise
  1643.                 end;
  1644.         GetGDToken;
  1645.         if Token = SemiColon then
  1646.             GetGDToken;
  1647.     end;
  1648.  
  1649.  
  1650.     procedure PutTokenBack2;
  1651.     begin
  1652.         if token <> DoneT then begin
  1653.                 pc := SavePC;
  1654.                 token := SaveToken;
  1655.             end;
  1656.     end;
  1657.  
  1658.  
  1659.     procedure DoGlobalDeclarations;
  1660.     begin
  1661.         GetGDToken;
  1662.         if (token = FunctionT) or (token = StringFunctionT) or (token = CommandT) or (token = ArrayT) then begin
  1663.                 LTMacroError('Predefined identifier');
  1664.                 exit(DoGlobalDeclarations);
  1665.             end;
  1666.         while ((token = UnknownIdentifier) or (token = Identifier)) and (Token <> DoneT) do
  1667.             DoGlobalDeclaration;
  1668.         PutTokenBack2;
  1669.     end;
  1670.  
  1671.  
  1672.     function PreScan1: boolean;
  1673.    {Converts the macro file to lowercase and removes comments.}
  1674.         var
  1675.             inString, inComment: boolean;
  1676.             c: char;
  1677.             i, StartComment, number: integer;
  1678.             line: string;
  1679.  
  1680.         function LineNumber: integer;
  1681.             var
  1682.                 i, n: integer;
  1683.         begin
  1684.             n := 1;
  1685.             for i := 0 to pc do
  1686.                 if MacroBufP^[i] = cr then begin
  1687.                         StartOfLine := i;
  1688.                         n := n + 1;
  1689.                     end;
  1690.             LineNumber := n;
  1691.         end;
  1692.  
  1693.     begin
  1694.         PreScan1 := false;
  1695.         inString := false;
  1696.         inComment := false;
  1697.         for i := 0 to EndMacros do begin
  1698.                 c := MacroBufP^[i];
  1699.                 if inString and (c = cr) then begin
  1700.                         pc := i - 1;
  1701.                         number := LineNumber;
  1702.                         line := CurrentLine;
  1703.                         PutError(StringOf('The quoted string in line ', number, ' of the macro file is not terminated.', line));
  1704.                         exit(PreScan1);
  1705.                     end;
  1706.                 if (not InString) and (c = '{') then begin
  1707.                         InComment := true;
  1708.                         StartComment := i;
  1709.                     end;
  1710.                 if inComment then begin
  1711.                         if (c = '{') and (i <> StartComment) then begin
  1712.                                 PutError(concat('Comments cannot be nested.', CurrentLine));
  1713.                                 exit(PreScan1);
  1714.                             end;
  1715.                         if c = '}' then
  1716.                             inComment := false;
  1717.                         if c <> cr then
  1718.                             MacroBufP^[i] := ' ';
  1719.                     end
  1720.                 else begin
  1721.                         if (c = '‘') or (c = '`') then begin
  1722.                                 pc := i;
  1723.                                 number := LineNumber;
  1724.                                 line := CurrentLine;
  1725.                                 PutError(StringOf('Bad quote("‘" or "`") in line ', number, ' of macro file.', line));
  1726.                                 exit(PreScan1);
  1727.                             end;
  1728.                         if c = '''' then
  1729.                             inString := not inString;
  1730.                         if (c >= 'A') and (c <= 'Z') and not inString then
  1731.                             MacroBufP^[i] := chr(ord(c) + 32);
  1732.                     end;
  1733.             end;
  1734.         if inComment then begin
  1735.                 pc := StartComment;
  1736.                 number := LineNumber;
  1737.                 line := CurrentLine;
  1738.                 PutError(StringOf('The comment starting in line ', number, ' of the macro file is not terminated.', line))
  1739.             end
  1740.         else
  1741.             PreScan1 := true;
  1742.     end;
  1743.  
  1744.  
  1745.     procedure StoreInteger (i: integer);
  1746.     begin
  1747.         with macrosP^ do begin
  1748.                 pc2 := pc2 + 1;
  1749.                 macros[pc2] := chr(band(bsr(i, 8), $ff));
  1750.                 pc2 := pc2 + 1;
  1751.                 macros[pc2] := chr(band(i, $ff));
  1752.             end;
  1753.     end;
  1754.  
  1755.  
  1756.     procedure StoreReal (r: real);
  1757.         type
  1758.             bytes=packed array[1..4] of char;
  1759.         var
  1760.             vrec:record
  1761.                 case integer of
  1762.                     1: (rv: real);
  1763.                     2: (b: bytes)
  1764.                 end;
  1765.     begin
  1766.         {b := bytes(r);} {ppc-bug}
  1767.         vrec.rv:=r;
  1768.         with macrosP^,vrec do begin
  1769.                 pc2 := pc2 + 1;
  1770.                 macros[pc2] :=b[1];
  1771.                 pc2 := pc2 + 1;
  1772.                 macros[pc2] :=b[2];
  1773.                 pc2 := pc2 + 1;
  1774.                 macros[pc2] :=b[3];
  1775.                 pc2 := pc2 + 1;
  1776.                 macros[pc2] := b[4];
  1777.             end;
  1778.     end;
  1779.  
  1780.  
  1781.     procedure StoreString;
  1782.         var
  1783.             i: integer;
  1784.     begin
  1785.         with macrosP^ do begin
  1786.                 for i := 1 to length(TokenStr) do begin
  1787.                         pc2 := pc2 + 1;
  1788.                         macros[pc2] := TokenStr[i];
  1789.                     end;
  1790.                 pc2 := pc2 + 1;
  1791.                 macros[pc2] := chr(0);
  1792.             end;
  1793.     end;
  1794.  
  1795.  
  1796.     procedure AddMenuItem;
  1797.         var
  1798.             i, fkey: integer;
  1799.             c, key: char;
  1800.     begin
  1801.         with MacrosP^ do begin
  1802.                 GetToken;
  1803.                 pc2 := pc2 + 1;
  1804.                 macros[pc2] := chr(ord(token));
  1805.                 if token <> StringLiteral then begin
  1806.                         LTMacroError('Macro command name not found');
  1807.                         exit(AddMenuItem);
  1808.                     end;
  1809.                 StoreString;
  1810.                 if nMacros < MaxMacros then begin
  1811.                         AppendMenu(SpecialMenuH, TokenStr);
  1812.                         nMacros := nMacros + 1
  1813.                     end
  1814.                 else
  1815.                     PutError('Too many macros.');
  1816.                 if macros[pc] = ';' then
  1817.                     pc := pc + 1;
  1818.                 MacroStart[nMacros] := pc2 + 1;
  1819.                 i := pos('[', TokenStr);
  1820.                 if i > 0 then begin {Assign a key to macro?}
  1821.                         i := i + 1;
  1822.                         key := TokenStr[i];
  1823.                         if (key >= 'A') and (key <= 'Z') then
  1824.                             key := chr(ord(key) + 32);
  1825.                         MacroKey[nMacros] := key;
  1826.                         if (key = 'f') and (TokenStr[i + 1] in ['1'..'9']) then begin {Function Key?}
  1827.                                 fkey := ord(TokenStr[i + 1]) - ord('0');
  1828.                                 if TokenStr[i + 2] in ['0'..'5'] then
  1829.                                     fkey := fkey * 10 + ord(TokenStr[i + 2]) - ord('0');
  1830.                                 if (fkey >= 1) and (fkey <= 15) then
  1831.                                     MacroKey[nMacros] := chr(ord('A') + fkey - 1);
  1832.                             end; {Function key?}
  1833.                     end;
  1834.             end; {with}
  1835.     end;
  1836.  
  1837.  
  1838.     procedure PreScan2;
  1839.   {Converts the macro file to a token stream. Some tokens are followed by an argument.}
  1840.   {<StringT> is followd by a null terminated string, <NumericLiteral> by a real(4 byte) number,}
  1841.   {<Identifier> and <ProcedureT> by a symbol table location (2 byte integer), and}
  1842.   {<CommandT>, <FunctionT>, <StringFunctionT> and <ArrayT> by a 1 byte ID.}
  1843.         var
  1844.             i: integer;
  1845.     begin
  1846.         with MacrosP^ do begin
  1847.                 if nMacros > 0 then
  1848.                     for i := 1 to nMacros do begin
  1849.                             DeleteMenuItem(SpecialMenuH, FirstMacroItem);
  1850.                             MacroKey[i] := chr(0);
  1851.                         end;
  1852.                 nMacros := 0;
  1853.                 nProcedures := 0;
  1854.                 nGlobals := 0;
  1855.                 if TopOfStack > 0 then
  1856.                     DeallocateStrings2(1, TopOfStack);
  1857.                 TopOfStack := 0;
  1858.                 MacroOrProcName := BlankSymbol;
  1859.                 pc := 0;
  1860.                 pc2 := 0;
  1861.                 token := NullT;
  1862.                 SymbolTableLoc := 0;
  1863.                 MacroLineNumber := 1;
  1864.                 repeat
  1865.                     GetToken;
  1866.                     macros[pc2] := chr(ord(token));
  1867.                     case token of
  1868.                         StringLiteral: 
  1869.                             StoreString;
  1870.                         NumericLiteral:
  1871.                             StoreReal(StringToReal(TokenStr));
  1872.                         MacroT:  begin
  1873.                                 AddMenuItem;
  1874.                                 if token = DoneT then
  1875.                                     exit(PreScan2);
  1876.                             end;
  1877.                         Identifier, ProcedureT, UserFunctionT: 
  1878.                             StoreInteger(SymbolTableLoc);
  1879.                         UnknownIdentifier:  begin
  1880.                                 AddIdentifier;
  1881.                                 if token = DoneT then
  1882.                                     exit(PreScan2);
  1883.                                 macros[pc2] := chr(ord(Identifier));
  1884.                                 StoreInteger(nSymbols);
  1885.                             end;
  1886.                         ProcIDT:  begin
  1887.                                 AddProcedure;
  1888.                                 if token = DoneT then
  1889.                                     exit(PreScan2);
  1890.                             end;
  1891.                         UserFuncIDT:  begin
  1892.                                 AddFunction;
  1893.                                 if token = DoneT then
  1894.                                     exit(PreScan2);
  1895.                             end;
  1896.                         VarT: 
  1897.                             if (nMacros = 0) and (nProcedures = 0) then begin
  1898.                                     DoGlobalDeclarations;
  1899.                                     if token = DoneT then
  1900.                                         exit(PreScan2);
  1901.                                 end;
  1902.                         CommandT, FunctionT, StringFunctionT, ArrayT: begin
  1903.                             pc2 := pc2 + 1;
  1904.                             macros[pc2] := chr(ord(MacroCommand));
  1905.                                 end;
  1906.                         otherwise
  1907.                             ;
  1908.                     end; {case}
  1909.                     pc2 := pc2 + 1;
  1910.                     if pc2 > (MaxMacroSize - 256) then begin
  1911.                             if nMacros > 0 then
  1912.                                 DeleteMenuItem(SpecialMenuH, FirstMacroItem + nMacros - 1);
  1913.                             PutError('Macro file is too large.');
  1914.                             EndMacros := MaxMacroSize;
  1915.                             exit(PreScan2);
  1916.                         end;
  1917.                 until token = DoneT;
  1918.                 EndMacros := pc2 - 1;
  1919.             end;
  1920.         if nMacros = 0 then
  1921.             PutError('No macros found.');
  1922.     end;
  1923.  
  1924.  
  1925.     procedure LoadMacros2;
  1926.     var
  1927.       size1, size2: LongInt;
  1928.       systemSymbols: integer;
  1929.     begin
  1930.         ShowWatch;
  1931.         size1 := endMacros;
  1932.         if not PreScan1 then begin
  1933.                 DisposePtr(ptr(MacroBufP));
  1934.                 exit(LoadMacros2);
  1935.             end;
  1936.         InitSymbolTable;
  1937.         systemSymbols := nSymbols;
  1938.         PreScan2;
  1939.         size2 := endMacros;
  1940.         DisposePtr(ptr(MacroBufP));
  1941.         CurrentX := 20;
  1942.         CurrentY := 20;
  1943.         SaveForeground := -1;
  1944.         StartOfLine := 0;
  1945.         ShowMessage(StringOf(
  1946.             'File size: ',size1:1, ' (', (size1 / MaxMacroFileSize) * 100.0:1:0, '%)', cr,
  1947.             'Tokenized: ', size2:1, ' (', (size2 / MaxMacroSize) * 100.0:1:0, '%)', cr,
  1948.             'Symbols: ', (nSymbols - systemSymbols):1, ' (', ((nSymbols - systemSymbols) / (maxSymbols - systemSymbols)) * 100.0:1:0, '%)', cr,
  1949.             'Macros: ', nMacros:1, ' (', (nMacros / maxmacros) * 100.0:1:0, '%)'));
  1950.     end;
  1951.  
  1952.  
  1953.     procedure LoadMacrosFromFile (fname: str255; RefNum: integer);
  1954.         var
  1955.             err: OSErr;
  1956.             FileSize: LongInt;
  1957.             f: integer;
  1958.     begin
  1959.         err := FSOpen(fname, RefNum, f);
  1960.         err := GetEOF(f, FileSize);
  1961.         if FileSize > MaxMacroFileSize then begin
  1962.                 err := fsclose(f);
  1963.                 PutError('Macro file is too large.');
  1964.                 exit(LoadMacrosFromFile);
  1965.             end;
  1966.         MacroBufP := MacroBufPtr(NewPtr(FileSize));
  1967.         if MacroBufP = nil then begin
  1968.                 err := fsclose(f);
  1969.                 PutError('Not enough memory to load macro file.');
  1970.                 exit(LoadMacrosFromFile);
  1971.             end;
  1972.         err := SetFPos(f, fsFromStart, 0);
  1973.         err := fsRead(f, FileSize, ptr(MacroBufP));
  1974.         EndMacros := FileSize - 1;
  1975.         err := fsclose(f);
  1976.         LoadMacros2;
  1977.     end;
  1978.  
  1979.  
  1980.     procedure LoadMacrosFromWindow;
  1981.         var
  1982.             ByteCount: LongInt;
  1983.     begin
  1984.         if TextInfo <> nil then
  1985.             with TextInfo^ do begin
  1986.                     ByteCount := TextTE^^.TELength;
  1987.                     if ByteCount <= 0 then begin
  1988.                             PutError('Text window is empty.');
  1989.                             exit(LoadMacrosFromWindow);
  1990.                         end;
  1991.                     EndMacros := ByteCount - 1;
  1992.                     MacroBufP := MacroBufPtr(NewPtr(ByteCount));
  1993.                     if MacroBufP = nil then begin
  1994.                             PutError('Not enough memory to load macros.');
  1995.                             exit(LoadMacrosFromWindow);
  1996.                         end;
  1997.                     BlockMove(TextTE^^.hText^, ptr(MacroBufP), ByteCount);
  1998.                     LoadMacros2;
  1999.                 end;
  2000.     end;
  2001.  
  2002.  
  2003.     procedure LoadMacros;
  2004.         var
  2005.             name: str255;
  2006.     begin
  2007.         if CurrentWindow = TextKind then
  2008.             LoadMacrosFromWindow
  2009.         else if GetTextFile(name, MacrosRefNum) then
  2010.             LoadMacrosFromFile(name, MacrosRefNum);
  2011.     end;
  2012.  
  2013.  
  2014. end.